<?php
namespace  App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use think\response\Json;

class Repair extends Model
{

        protected $table = 'repair';//表名
        protected $fillable = ['order_id','username','address','number','community_id','desc','status','type','service_at'];//白名单

    public function indexPage($page,$limit)
    {
        $start = ($page-1)*$limit;
        $res = $this->where('status',1)->offset($start)->limit($limit)->orderBy('updated_at','desc')->get();
        return $res;
    }

    public function indexPageLike($page,$limit,$condition)
    {
        $start = ($page-1)*$limit;
        $query = 'SELECT * FROM `repair` WHERE `status` = 1 and CONCAT(`order_id`,`desc`,`username`,`address`,`service_at`,`type`) LIKE ?  ORDER BY(updated_at) desc  limit ?,?';
        $param = '%'.$condition.'%';
        $res = DB::select($query , array($param,$start,$limit));
        return json_decode(json_encode($res),true);
    }
}
